package cn.itcast.bos.web.action.base;

import cn.itcast.bos.domain.base.SubArea;
import cn.itcast.bos.service.base.SubAreaService;
import cn.itcast.bos.web.action.common.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.io.File;
import java.util.List;

@Controller
@ParentPackage("json-default")
@Namespace("/")
@Scope("prototype")
public class SubAreaAction extends BaseAction<SubArea> {

    @Autowired
    private SubAreaService subAreaService;

    //分页查询分区信息
    @Action(value = "subArea_pageQuery", results = { @Result(name = "success", type = "json") })
    public String queryPage(){
        // 构造分页查询对象
        Pageable pageable = new PageRequest(page - 1, rows);
        // 构造条件查询对象
        Specification<SubArea> specification = new Specification<SubArea>() {
            @Override
            public Predicate toPredicate(Root<SubArea> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                return null;
            }
        };
        Page<SubArea> pages = subAreaService.findPageData(specification,pageable);
        pushPageDataToValueStrack(pages);

        return SUCCESS;
    }



    //分区导入subArea_batchImport
    private File file;
    private String fileFileName;
    public void setFile(File file) {
        this.file = file;
    }
    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }

    @Action(value = "subArea_batchImport")
    public String batchImport(){
//        subAreaService.uploadArea(file,fileFileName);

        return NONE;
    }



}
